﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Ct_Aliyun;
namespace ceshi
{
    class Program
    {
        private static string DirToDownload = "Remote/";

        private static string FileToUpload = @"D:\云韵.png";

        private static string BigFileToUpload = @"D:\555.mp4";
        private static string ImageFileToUpload = @"D:\yunmi.png";
        private static string CallbackServer = "www.baidu.com";
        private static string bucketName = "image-12345685";
        /// <summary>
        /// SDK的示例程序
        /// </summary>
        public static void Main(string[] args)
        {

            Console.WriteLine("Aliyun SDK for .NET Samples!");



            try
            {



                OssCenter ossCenter = OssCenter.CreateOssCenter("LTAI5t87LnK6rSfhxbePUzTW", "3gMXCjnDmGQvuDtBUyIQYS6eWgNJ3m", "oss-cn-beijing.aliyuncs.com");

                //---------------------------------------------------------------------------------------

                //OssTaskRequest ossTaskReques = new OssTaskRequest();
                //ossTaskReques= ossCenter.DownloadObjectRawDataAsync(bucketName, "Remote/yunmi.png",(RequestState) => {
                //    Console.WriteLine("下载完成");
                //});
                //while (!ossTaskReques.completed)
                //{
                //    Console.WriteLine("当前进度："+ ossTaskReques.progress.ToString());
                //}
                //Console.WriteLine("下载结果：" + ossTaskReques.content.Length.ToString());




                //---------------------------------------------------------------------------------------



                // ossCenter.Download(bucketName, "Remote/yunmi.png", @"D:\");

                //---------------------------------------------------------------------------------------

                //ossCenter.DownloadAsync(bucketName, "Remote/yunmi.png", @"D:\", (RequestState) => { Console.WriteLine("下载完成"); });


                //---------------------------------------------------------------------------------------

                // ossCenter.Upload(bucketName, ImageFileToUpload, "Remote/", SaveFileName: "yunmi4.png");


                //---------------------------------------------------------------------------------------


                //using (FileStream fs = File.OpenRead(ImageFileToUpload))
                //{

                //    int length = 1024*4;
                //    byte[] res=null;
                //    using (MemoryStream ms = new MemoryStream())
                //    {
                //        byte[] data = new byte[length];
                //        while (length != 0)
                //        {

                //            length = fs.Read(data, 0, length);

                //            BinaryWriter binaryWriter = new BinaryWriter(ms);
                //            binaryWriter.Write(data,0,length);

                //        }
                //        res = ms.ToArray();
                //    }

                //    ossCenter.UploadRawData(bucketName, res, "Remote/", SaveFileName: "yunmi8.png");
                //}


                //---------------------------------------------------------------------------------------

                //using (FileStream fs = File.OpenRead(ImageFileToUpload))
                //{

                //    int length = 1024 * 4;
                //    byte[] res = null;
                //    using (MemoryStream ms = new MemoryStream())
                //    {
                //        byte[] data = new byte[length];
                //        while (length != 0)
                //        {

                //            length = fs.Read(data, 0, length);

                //            BinaryWriter binaryWriter = new BinaryWriter(ms);
                //            binaryWriter.Write(data, 0, length);

                //        }
                //        res = ms.ToArray();
                //    }

                //    ossCenter.UploadRawDataAsync(bucketName, res, "Remote/", (RequestState) => { Console.WriteLine("完成"); });
                //}
                //---------------------------------------------------------------------------------------



                Console.ReadKey(true);

            }



            catch (Exception ex)
            {
                Console.WriteLine("Failed with error info: {0}", ex.Message);
            }

            Console.WriteLine("Press any key to continue . . . ");



            Console.ReadKey(true);
        }

    }
}
